package com.orharlan.carassistant.features;

import com.orharlan.carassistant.datamodel.Datamodel;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class AppService extends Service
{

	private Datamodel data;

	@Override
	public IBinder onBind( Intent intent )
	{
		// This procedure is not necessary for my purpose. It is used for
		// Bounded Services
		return null;
	}

	@Override
	public void onCreate( )
	{
		System.out.println( System.currentTimeMillis( ) + ": AppService created" );
		// Keep assignment to the rootObject
		data = Datamodel.singleton( );

	}

	@Override
	public int onStartCommand( Intent intent, int flags, int startId )
	{

		// If the Service started, it will call this procedure
		System.out.println( System.currentTimeMillis( ) + ": AppService started" );

		// Weather Query
		if( data.getCurrentLatitude( ) != 0.0 && data.getCurrentLongitude( ) != 0.0 )
		{
			GetWoeid woeid = new GetWoeid( );
			woeid.startQuery( );
			GetWeather weather = new GetWeather( );
			weather.startQuery( );
		}

		// If the procedure finished his job, we have to stop the Service
		stopSelf( );

		// The Service should run until the operating system quit it. In this
		// case we return "START_STICKY"
		return START_STICKY;
	}

	@Override
	public void onDestroy( )
	{
		System.out.println( System.currentTimeMillis( ) + ": AppService destroyed" );

	}

}